#include <stdio.h>
#include <stdlib.h>

FILE *file_open(const char *path, const char *mode);
int file_close(FILE **fp);

int main(int argc, char const *argv[])
{
    FILE * fp = file_open("hello.txt" , "a+");

    fprintf(fp ,"今天天气正好\n");

    file_close(&fp);
    return 0;
}



FILE *file_open(const char *path, const char *mode)
{
    FILE *fp = fopen(path, mode);
    if (NULL == fp)
    {
        printf("文件创建失败\n");
        exit(-1);    // 退出整个程序
    }
    return fp;
}

int file_close(FILE **fp)
{
    fclose(*fp);
    *fp = NULL;
}
